

// const path = require("node:path");
// // fs也需要引入
// const fs = require("node:fs")

// 同步的方法，会影响后面的代码执行

/* const buf = fs.readFileSync(path.resolve(__dirname,"./note.txt"))

console.log(buf.toString());
 */

// 异步的方法，不会影响后面的代码执行

/* fs.readFile(
    path.resolve(__dirname,"./note.txt"),
    (err,buffer)=>{
        if(err){
            console.log("出错了");
        }else{
            console.log(buffer.toString());
        }

    }
)

console.log("我先执行"); */

// promise异步 

const path = require("node:path");
const fs = require("node:fs/promises")

/* fs.readFile(path.resolve(__dirname,"./note.txt"))
    .then(buffer => {
        console.log(buffer.toString());
    })
    .catch(e => {
        console.log("出错了");
    }) */
    
 
//async

;(async () => {
    try{
        const buffer = await fs.readFile(path.resolve(__dirname,"./note.txt"))
        console.log(buffer.toString());
    }
    catch(e){
        console.log("出错了");
    }
})()

// fs.mkdir(path.resolve(__dirname,"./hello"))
    .then(r => {
        console.log("创建成功");
    }).catch(err => {
        console.log("创建失败");
    })




fs.rmdir(path.resolve(__dirname,"./hello"))
    .then(r => {
        console.log("删除成功");
    })